import request from '@/utils/request'

// 菜单查询参数
export interface MenuQueryParams {
  menuName?: string
  status?: number
}

// 创建菜单请求
export interface CreateMenuRequest {
  parentId?: number
  menuName: string
  menuType: number
  path?: string
  component?: string
  permission?: string
  icon?: string
  sort?: number
  isFrame?: number
  isCache?: number
  visible?: number
  status?: number
  remark?: string
}

// 更新菜单请求
export interface UpdateMenuRequest {
  parentId?: number
  menuName: string
  menuType: number
  path?: string
  component?: string
  permission?: string
  icon?: string
  sort?: number
  isFrame?: number
  isCache?: number
  visible?: number
  status?: number
  remark?: string
}

// 菜单API
export const menuApi = {
  // 获取菜单树
  getMenuTree: () => {
    return request.get('/menus/tree')
  },

  // 获取当前用户菜单树
  getUserMenuTree: () => {
    return request.get('/menus/user-tree')
  },

  // 获取所有菜单列表
  getMenuList: (params: MenuQueryParams) => {
    return request.get('/menus/list', { params })
  },

  // 根据父菜单ID获取子菜单
  getMenusByParentId: (parentId: number) => {
    return request.get(`/menus/children/${parentId}`)
  },

  // 获取菜单详情
  getMenuById: (id: number) => {
    return request.get(`/menus/${id}`)
  },

  // 新增菜单
  createMenu: (data: CreateMenuRequest) => {
    return request.post('/menus', data)
  },

  // 更新菜单
  updateMenu: (id: number, data: UpdateMenuRequest) => {
    return request.put(`/menus/${id}`, data)
  },

  // 删除菜单
  deleteMenu: (id: number) => {
    return request.delete(`/menus/${id}`)
  },

  // 批量删除菜单
  batchDeleteMenu: (ids: number[]) => {
    return request.delete('/menus/batch', { data: { ids } })
  },

  // 启用/禁用菜单
  changeStatus: (id: number, status: number) => {
    return request.put(`/menus/${id}/status`, { status })
  },

  // 检查菜单是否有子菜单
  hasChildren: (id: number) => {
    return request.get(`/menus/${id}/has-children`)
  }
} 